float V_OFFSET = 10;
int H = 2;
int W = 5;
boolean locked = false;

BP[] bps = {};
RNA r;

void setup()
{
    size(20, 700);
    fill(200);
    r = new RNA();
    noStroke();
     for (int i = 0; i < height; i+=V_OFFSET) {
        bps = (BP[]) append(bps, new BP(W, H, 0, i));
    }
}

void draw()
{
  background(0);
  update();
}

void update() {
    for (BP b : bps) {
        b.update();
    }
}

void mousePressed() {
    locked = true;
    //r.startS();
}

void mouseReleased() {
    locked = false;
    //r.endS();
}


class BP 
{
    float w; // width
    float h; // height
    int xPos, yPos;
    boolean right = false;
    boolean center = false;

    BP(float iw, float ih, int ixPos, int iyPos) {
        w = iw;
        h = ih;
        xPos = ixPos;
        yPos = iyPos;
    }
    
    float inRange() {
        int RANGE = 30;
        if (abs(mouseY - this.yPos) < RANGE) {
            return 30.0 / abs(mouseY - this.yPos);
        }
        return 0;
    }

    void adjust(float newW) {
        this.w = newW;
    }

    void display() {
        if (center) {
            rect(width/2 - w/2, yPos, w, h);   
        } else {
            rect(xPos, yPos, w, h);
            rect(width - w, yPos, w, h);
        }
    }
    
    void update() {
//        if (inRange() > 0) {
//            w = inRange()+W;
//        } else {
//            w = W;
//        }
        if (yPos > mouseY) {
            center = true;
            w = 20.0 * cos((mouseY - yPos) / 40.0);
        }
        else {
            center = false;
            w = W;
        }
        display();
        r.update();
    }
}

class RNA {
    int s, e;
    int RNA_X = 7;
    BP[] rna = {};
    
    RNA() {
    }
    
    void startS() {
        s = mouseY;
        e = mouseY;
    }
    
    void update() {
        fill(50, 100, 50);
        if (locked) {
            BP b = new BP(W, H, RNA_X, int(mouseY - (mouseY%V_OFFSET)));
            b.center = true;
            rna = (BP[]) append(rna, b);
        }
        for (BP bs : rna) {
                bs.display();
            }
        fill(100);
    }
    
    void endS() {
        rna = new BP[0];
    }
}

